package bx.job.httpserver.actor;

import akka.actor.typed.ActorRef;
import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.Receive;
import bx.InteractionEntity.CommonResponse;
import bx.InteractionEntity.WorkerRegistRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JobWorkerRegistProcessorActor extends AbstractBehavior<JobWorkerRegistProcessorActor.JobWorkerRegistProcessorActorMsg> {
    private final static Logger log = LoggerFactory.getLogger(JobWorkerRegistProcessorActor.class);

    public interface JobWorkerRegistProcessorActorMsg {
    }

    public static record JobWorkerRegistMsg(WorkerRegistRequest registRequest,
                                            ActorRef<JobWorkerRegistInfo> replyTo) implements JobWorkerRegistProcessorActorMsg {
    }

    public static class JobWorkerRegistInfo extends CommonResponse implements JobWorkerRegistProcessorActorMsg {
    }

    public JobWorkerRegistProcessorActor(ActorContext<JobWorkerRegistProcessorActorMsg> context) {
        super(context);
    }

    public static Behavior<JobWorkerRegistProcessorActorMsg> create() {
        return Behaviors.setup(JobWorkerRegistProcessorActor::new);
    }

    @Override
    public Receive<JobWorkerRegistProcessorActorMsg> createReceive() {
        return newReceiveBuilder()
                .onMessage(JobWorkerRegistMsg.class, this::onJobWorkerRegistMsg)
                .build();
    }

    private Behavior<JobWorkerRegistProcessorActorMsg> onJobWorkerRegistMsg(JobWorkerRegistMsg jobWorkerRegistMsg) {
        log.info("regist success");
        JobWorkerRegistInfo jobWorkerRegistInfo = new JobWorkerRegistInfo();
        jobWorkerRegistInfo.setMsg("success");
        jobWorkerRegistInfo.setStatus(JobWorkerRegistInfo.SUCCESS_STATUS);
        jobWorkerRegistMsg.replyTo().tell(jobWorkerRegistInfo);
        return this;
    }


}
